<?php
/**
* 可用脚本登记
*
* 说明：type 可选值[enum,number,enumber,string,estring,date]
*		type == enum 时，可设置 [options,min,max]
* @author     王鹏
* @version    1.0
* @copyright  商业软件,受著作权保护
*/

$aRule['/admin/xuanyouUser/feedback'] = array(
	'page' => array ('type'=>'number'),
);
$aRule['/admin/xuanyouUser/postlog'] = array(
	'page' => array ('type'=>'number'),
);
$aRule['/admin/xuanyouUser/mail'] = array(
	'page' => array ('type'=>'number'),
);


$aRule['/admin/xuanyouUser/view'] = array(
	'id' => array ('type'=>'number'),
);

$aRule['/admin/xuanyouUser/opt'] = array(
	'act' => array ('type'=>'enum', 'options'=>array("del")),
	'id' => array ('type' => 'number'),
);

$aRule['/admin/xuanyouUser/viewargs'] = array(
	'act' => array ('type'=>'enum', 'options'=>array("view")),
	'id' => array ('type' => 'number'),
);
$aRule['/admin/xuanyouUser/postlog'] = array(
	'act' => array ('type'=>'enum', 'options'=>array("view","ip","cookie","search")),
	'z' => array ('type' => 'string', "maxlength"=>32, 'mast'=>'N'),
	'page' => array ('type'=>'number', 'mast'=>'N'),
);

$aRule['/admin/xuanyouProduct/opt'] = array(
	'act' => array ('type'=>'enum', 'options'=>array("close","open")),
	'id' => array ('type' => 'number'),
);
$aRule['/admin/xuanyouProduct/search'] = array(
	'page' => array ('type'=>'number'),
);
$aRule['/admin/manager/logs'] = array(
	'page' => array ('type'=>'number'),
);
######################################## 以下是路由部分 ##########################################

/*
---------------------------------------------------------------------
- 功能描述: 管理后台路由表
- 版本: 1.0
- 原作者:wangpeng
- 编写日期:2012-5-31
- 运行环境:---
---------------------------------------------------------------------
*/
class Router extends Base
{
	public $rule = array();

	/**
	 * 构造函数
	 *
	 * @access public
	 * @param
	 * @return void
	 */
	function __construct($rule)
	{
		global $aRule;
		$this->rule = $rule;

		$tmp = explode("?", $_SERVER['REQUEST_URI']);
		$requrest_lower = strtolower($tmp[0]);
		
		// ?号前半部分不是小写，重定向到小写
		if($requrest_lower != $tmp[0])
		{
			Common::header($requrest_lower . '?' . $tmp[1]);
		}

		//载入函数
		Common::loadFunc("Admin");

		$this->parseUri($_SERVER['REQUEST_URI']);
	}
	
	/**
	 * 解析REQUEST_URI
	 *
	 * @access public
	 * @param
	 * @return void
	 */
	public function parseUri($request_uri)
	{
		//当前频道
		parent::$channel = "admin";
		header("Cache-Control: no-store, no-cache, must-revalidate");

		$parseArr = parse_url($request_uri);
		parse_str($parseArr['query'], $args);
		$pathArr = explode("/", $parseArr['path']);

		//首页快速解析
		if($request_uri == '/')
		{
			parent::$controller = "sys";
			parent::$action = "index";
		}
		//系统文件
		else if(in_array($pathArr[1], array("login.html", "kflogin.html", "logout.html", "leftmenu.html", "indexbody.html", "repass.html", "vdimgck.html")))
		{
			parent::$controller = "sys";
			parent::$action = substr($pathArr[1], 0, -5);
		}
		//其他
		else
		{
			//echo $args['type'];
			if($pathArr[3])
			{
				parent::$controller = $pathArr[1].ucfirst($pathArr[2]);
				parent::$action = substr($pathArr[3], 0, -5);
			}
			else
			{
				parent::$controller = $pathArr[1];
				$actMain = $args['act'] == '' ? "" : $args['act'];
				parent::$action = substr($pathArr[2], 0, -5).ucfirst($actMain);
			}

			//检查GET参数的合法性
			Check::gets($this->rule, parent::$channel, parent::$controller, parent::$action, $args);

			parent::$args = $args;
		}

		//调试
		if($args['debug'] == 'on')
		{
			parent::$debug = true;
		}

		/* 启用SESSION */
		session_start();

		//设置默认分页条数
		if(!$_SESSION['libvar']['pageset'])
		{
			$_SESSION['libvar']['pageset'] = 20;
		}

		//管理员登录信息
		parent::$admin = $_SESSION['admin'];
	}
}
?>